package Database;

import java.util.Scanner;

/**
 * @Author mao
 * @Date 2025/11/25
 * @Description 控制台程序
 */
public class WebsiteDB {
    public static int getChoose(){
        System.out.println("-----------------------------");
        System.out.println(" 1. 添加网站         2. 删除网站");
        System.out.println(" 3. 修改网站         4. 查询网站");
        System.out.println(" 0. 退出数据库操作工具");
        System.out.println("-----------------------------");
        System.out.print("请选择你的操作:");
        Scanner sc = new Scanner(System.in);
        return sc.nextInt();
    }

    public static void main(String[] args) {
        MySQLController mySQLController = new MySQLController();
        Scanner sc = new Scanner(System.in);
        System.out.println("欢迎访问网站数据库");
        while (true){
            int choose = getChoose();
            if (choose == 1) {
                Website newWebsite = new Website();
                mySQLController.addWebsite(newWebsite);
            } else if (choose == 2) {
                System.out.println("请输入要删除的网站名:");
                mySQLController.deleteWebsite(mySQLController.selectWebsite(sc.next()));
            } else if (choose == 3) {
                System.out.println("请输入要修改的网站名:");
                mySQLController.updateWebsite(mySQLController.selectWebsite(sc.next()));
            } else if (choose == 4) {
                System.out.println(" 1. 根据网站名查询   2. 显示所有数据");
                System.out.print("请选择查询方式:");
                int selectChoose = sc.nextInt();
                if (selectChoose == 1){
                    System.out.print("请输入要查询的网站名:");
                    mySQLController.selectWebsite(sc.next());
                }else {
                    System.out.println("数据库的全量数据如下:");
                    mySQLController.selectAllWebsite();
                }
            } else if (choose == 0) {
                mySQLController.closeConnection();
                System.out.println("欢迎您再次使用");
                break;
            }else {
                System.out.println("请输入正确的选项");
            }
        }
    }
}
